#ifndef ALP_H
#define ALP_H

#include <stddef.h>
#include <errno.h>
#include <stdio.h>
#include <memory.h>

#ifdef __cplusplus
#define ALP_EXTERN extern "C" 
#else
#define ALP_EXTERN
#endif

#ifdef ALP_DECLARE_EXPORT
#define ALP_DECLARE(type) ALP_EXTERN __declspec(dllexport) type
#else
#define ALP_DECLARE(type) ALP_EXTERN type
#endif

typedef int alp_status_t;

#define ALP_CHECK(f) { alp_status_t ret = f; if (ret) return ret; }

#ifdef _MSC_VER

#if _MSC_VER > 1400
#define _CRT_SECURE_NO_DEPRECATE
#endif

#include <malloc.h>
#define ALP_ALLOCA _malloca
#undef ALP_VALLOC
#define ALP_MALLOC_SIZE _msize

#define ALP_ICONV_MLANG

#else // _MSC_VER

// POSIX

#define ALP_ALLOCA alloca

#undef ALP_ICONV_MLANG

#if defined(__APPLE__)

#define ALP_VALLOC(x)   malloc(malloc_good_size(x))
#define ALP_MALLOC_SIZE malloc_size

#else // __APPLE__

#define ALP_VALLOC      valloc
#define ALP_MALLOC_SIZE malloc_usable_size

#endif

#endif // _MSC_VER

#endif
